package cn.itcast.controller;

import cn.itcast.domain.User;
import cn.itcast.entity.Result;
import cn.itcast.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by leiylong on 2020/5/19
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("/add")
    public Result addUser(User user) {
        userService.add(user);
        return new Result();
    }
    /**
     * restful风格url
     * @param id
     * @return
     */
    @RequestMapping(value = "/user/{id}")
    @ResponseBody
    public User selectUser(@PathVariable("id") Integer id){
        System.out.println("id="+id);
        User user=new User();
        if(id.equals(123)){
            user.setPassword("123456");
            user.setUsername("张三");
        }
        return user;
    }
}
